N = 200 + 5
inf = int(1e9)
dis = [[0 for i in range(0, N)] for j in range(0, N)]

n = int(input())

for i in range(1, n + 1):
    s = input().split()
    for j in range(1, n + 1):
        dis[i][j] = int(s[j - 1])
    for j in range(1, i):
        dis[i][j] =  inf
for k in range(1, n + 1):
    for i in range(1, n + 1):
        for j in range(1, n + 1):
            dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j])

print(dis[1][n]) 